<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts'
// require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
// import { indexHistogram } from '@/api/index'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '500px'
    }
  },
  data() {
    return {
      chart: null,
      mouth: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
      orderMouth: [345, 212, 456, 187, 390, 267, 412, 389, 276, 198, 432, 310],
      putCount: [289, 376, 190, 423, 256, 387, 156, 478, 234, 321, 178, 409],
      params: {
        selectDate: '2024-07-01'
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        title: {
          text: '任务数据概览',
          textStyle: {
            color: '#999', // 设置标题颜色为深灰色
            fontSize: 14
          }
          // subtext: 'Fake Data'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['采样', '检验'],
          bottom: '0%',
          left: 'center',
        },
        toolbox: {
          show: true,
          iconStyle: {
            // color: '#999', // 设置工具栏图标颜色为深灰色
            borderColor: '#999'
          },
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            // prettier-ignore
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '采样',
            type: 'line',
            data: this.putCount,
            barWidth: 18,
            itemStyle: {
              color: '#ffdd60', // 修改 Rainfall 的颜色为 royal blue

            },
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                { type: 'min', name: 'Min' }
              ]
            },
            markLine: {
              data: [{ type: 'average', name: 'Avg' }]
            }
          },
          {
            name: '检验',
            type: 'line',
            data: this.orderMouth,
            barWidth: 18,
            itemStyle: {
              color: '#458bfa',// 修改 Rainfall 的颜色为 royal blue

            },
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                { type: 'min', name: 'Min' }
              ]
            },
            markLine: {
              data: [{ type: 'average', name: 'Avg' }]
            }
          }
        ]
      })
    }
  }
}
</script>
